package com.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Administrator on 2016/7/8.
 */
public class WeekTextView extends View {
    private Context context;
    private Paint paint;
    private Rect textRect;
    private float fontSpace ;
    private int textColor = android.R.color.black;
    private String weekTexts[] = new String[]{"日", "一", "二", "三", "四", "五", "六"};
    public WeekTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        initWeekTextView();
    }

    private void initWeekTextView() {
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(context.getResources().getColor(textColor));
        textRect = new Rect();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        float parentWidth = (float) getWidth();
        float parentHeight = (float) getHeight();
        fontSpace = parentWidth * 0.115f;
        paint.setTextSize(parentWidth * 0.05f);
        paint.getTextBounds(weekTexts[0], 0, weekTexts[0].length(), textRect);
        float start = (parentWidth - 7 * textRect.width() - 6 * fontSpace) / 2.0f;
        for (int i = 0; i < weekTexts.length; i++) {
            canvas.drawText(weekTexts[i], start + i * (textRect.width() + fontSpace), (parentHeight + textRect.height()) / 2, paint);
        }

    }
}
